using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using IGlobalist.Cms.Common;
using System.Collections.Generic;
using IGlobalist.Cms.Bll;
using IGlobalist.Cms.Model;

namespace IGlobalist.Cms.Admin.Control
{
    public partial class TemplateList : AdminBaseUserControl
    {
        public event EventHandler BindUpdateTemplate; 
        
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public void BindGridView(object sender, EventArgs e)
        {
            ClassList list = (ClassList)sender;
            long classID = Convert.ToInt64(list.SelectedValue);
            Session[SessionVariable.Clazz.CurrentID] = classID.ToString();
            ICmsClass clazz =  ClassController.GetClass(classID);
            lblStatus.Text = String.Format("Template list of class {0} ",clazz.Name);
            IList<Cms.Model. ITemplate> tempL = TemplateController.GetTemplateListByClass(classID);
            gvTemplate.DataSource = tempL;
            gvTemplate.DataBind();
        }
        public void BindGridViewRefesh(object sender, EventArgs e)
        {
            BindRefeshGridView();
        }
        public void BindRefeshGridView()
        {
            long classID = Convert.ToInt64(Session[SessionVariable.Clazz.CurrentID]);            
            IList<Cms.Model.ITemplate> tempL = TemplateController.GetTemplateListByClass(classID);
            if (tempL != null)
            {
                gvTemplate.DataSource = tempL;
                gvTemplate.DataBind();
            }
        }
        public string SelectedID
        {
            get { return (string)ViewState["templateID"]; }
            set { ViewState["templateID"] = value; }
        }
        protected void ibUpdate_Click(object sender, ImageClickEventArgs e)
        {
            ImageButton ibDelete = (ImageButton)sender;
            long ID = Convert.ToInt64(ibDelete.CommandArgument);
            SelectedID = ID.ToString();
            if (BindUpdateTemplate != null)
            {
                BindUpdateTemplate(this, new EventArgs());
            }
        }
        protected void ibDelete_Click(object sender, ImageClickEventArgs e)
        {
            ImageButton ibDelete = (ImageButton)sender;
            long ID = Convert.ToInt64(ibDelete.CommandArgument);
            TemplateController.DeleteTemplate(ID);
            BindRefeshGridView();

        }
        public void DoHidden(object sender, EventArgs e)
        {
            this.Visible = false;
        }
        public void DoShow(object sender, EventArgs e)
        {
            this.Visible = true;
            BindRefeshGridView();
        }

    }
}